public class Class02 {
    public static void main(String[] args) {
        //
        int[][] arr = new int[][]{
                {2,6,15,23,45},
                {4,7,6,3,16,28},
                {34,26,96,36,24},
                {15,34,92,766,52},
                {156,95,15,59,11}
        };
        int min = arr[0][0];
        int indexX = 0;
        int indexY = 0;
        for (int i = 0; i < arr.length ; i++) {
            for (int j = 0; j < arr[i].length ; j++) {
                if (min > arr[i][j]){
                    min = arr[i][j];
                    indexX = i ;
                    indexY = j ;
                }
            }
        }
        System.out.println("最小值是：" + min);
        System.out.println("最小值坐标是：" + indexX + ", " + indexY);
        int sum = (indexY == 0 ? 0 : arr[indexX][indexY - 1]) // 左边
                + (indexY == arr[0].length - 1 ? 0 : arr[indexX][indexY + 1]) // 右边
                + (indexX == 0 ? 0 : arr[indexX - 1][indexY]) // 正上方
                + (indexX == arr.length - 1 ? 0 : arr[indexX + 1][indexY]) // 正下方
                + (indexX == 0 || indexY == 0? 0 : arr[indexX - 1][indexY - 1])// 斜左上方
                + (indexX == 0 || indexY == arr[0].length - 1? 0 : arr[indexX - 1][indexY + 1]) // 斜右上方
                + (indexY == 0 || indexX == arr.length - 1? 0 : arr[indexX + 1][indexY - 1])// 斜左下方
                + (indexX == arr.length - 1 || indexY == arr[0].length - 1? 0 : arr[indexX + 1][indexY + 1]); // 斜右下方
        System.out.println(sum);
    }
}
